Conversation
…lds (#2411) Nullable typed JSON fields (e.g. `field: MyType? @json`) now correctly accept DbNull, JsonNull, and AnyNull in create/update inputs and where filters, matching the behavior of untyped `Json?` fields. AnyNull is rejected at the TypeScript level for create/update inputs since it has no semantic meaning there, but is accepted in where filters. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job PR Review Complete ✅I've thoroughly reviewed this pull request and the implementation looks solid. Here's my detailed assessment: 📋 SummaryThis PR successfully addresses issue #2411 by adding support for 🔍 Code Quality AssessmentType Definitions (
Schema Generation (
Dialect Handling (
🧪 Test Coverage - ComprehensiveThe regression test in
🔒 Security & PerformanceSecurity: ✅ No concerns - proper input validation through Zod schemas ⚡ Potential Issues & ConsiderationsMinor Concerns:
Edge Case Considerations:
🎯 Suggestions for ImprovementLow Priority:
✅ Approval Checklist
🏆 Overall AssessmentThis is a high-quality implementation that successfully resolves a complex type system issue. The author has:
The implementation demonstrates strong understanding of the codebase architecture and TypeScript's advanced type system. Recommendation: ✅ Approve and merge |
📝 WalkthroughWalkthroughThese changes add TypeScript typing support for null sentinel values (DbNull, JsonNull, AnyNull) when used with optional custom JSON fields in mutations and filters. Updates include refined type unions, validation schema generation, and comprehensive regression tests verifying the behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/orm/src/client/crud/dialects/base-dialect.ts`:
- Around line 573-577: The check for null sentinels only handles root-level
fields in the isTypeDef branch and misses nested typed-JSON recursion; update
the recursive path inside buildTypeJsonNonArrayFilter (and any helper that walks
typedef members) to detect payload instances of DbNullClass, JsonNullClass, or
AnyNullClass and route them to buildJsonValueFilterClause(fieldRef, payload)
instead of treating them as empty-object no-ops; specifically, add the same
instanceof checks and call to buildJsonValueFilterClause where nested member
payloads are processed so expressions like { metadata: { nested: DbNull } } or {
optionalMetadata: { is: JsonNull } } produce JSON-null predicates.
In `@tests/regression/test/issue-2411/regression.test.ts`:
- Around line 72-76: Seed four distinct rows via db.foo.create (or the test
suite's seeding helper) where optionalMetadata is set to values that should be
matched by each sentinel, then replace the loose findMany calls with assertions
that verify the returned ids/counts exactly match the expected row for each
sentinel: call db.foo.findMany({ where: { optionalMetadata: DbNull } }),
db.foo.findMany({ where: { optionalMetadata: JsonNull } }), db.foo.findMany({
where: { optionalMetadata: AnyNull } }) and db.foo.findMany({ where: {
optionalMetadata: null } }) and assert each returns only the seeded row(s)
intended for that sentinel (compare ids or length), so the test verifies actual
semantics of db.foo.findMany, optionalMetadata, DbNull/JsonNull/AnyNull rather
than just type acceptance.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4c92bbe6-91e3-455e-bf43-607afb207d42
📒 Files selected for processing (8)
packages/orm/src/client/crud-types.tspackages/orm/src/client/crud/dialects/base-dialect.tspackages/orm/src/client/zod/factory.tstests/regression/test/issue-2411/input.tstests/regression/test/issue-2411/models.tstests/regression/test/issue-2411/regression.test.tstests/regression/test/issue-2411/schema.tstests/regression/test/issue-2411/schema.zmodel
Summary
Fixes #2411
field: MyType? @json) now acceptDbNullandJsonNullsentinels without TypeScript errors.AnyNullis rejected at the TypeScript level (no semantic meaning for mutation) and rejected at runtime.DbNull,JsonNull, andAnyNullpassed directly (e.g.where: { field: DbNull }), matching untypedJson?field behavior.DbNull,JsonNull,AnyNullremain rejected at the TypeScript level.Changes
crud-types.ts: AddedIsTypedJsonFieldtype helper; extendedScalarFieldMutationPayloadto includeDbNull | JsonNullfor nullable typed JSON fields; extendedTypedJsonTypedFilterto includenull | JsonNullValuesfor optional typed JSON fields in where clauses.zod/factory.ts: ExtractedmakeNullableTypedJsonMutationSchemahelper (used by both create and update schema builders); added null sentinel types tomakeTypedJsonFilterSchemafor optional fields; replaced inlinethis.schema.typeDefs && fieldDef.type in this.schema.typeDefswith existingisTypeDefType().dialects/base-dialect.ts: Intercepts null sentinels passed directly in where clauses for typed JSON fields and routes them tobuildJsonValueFilterClause.Test plan
tests/regression/test/issue-2411/using the exact schema from the issuetsc --noEmit)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests